
        /*
        This code works automaticaly for this type of nesting:

        <div class="myFAQ">
            <div>
                <h3>Question 1</h3>
                <div>
                    <p>Answer 1</p>
                </div>
            </div>
            <div>
                <h3>Question 2</h3>
                <div>
                    <p>Answer 2</p>
                </div>
            </div>
        </div>
       */

      
            var animationSpeed = 300; // in ms

            function hideItem(item) {
                item.animate({
                    height: "0px"
                }, animationSpeed, function () {
                    // Animation complete.
                    item.removeAttr("style");
                });
            }

            function showItem(item) {
                item.css("height", "auto");
                var itemHeight = item.css("height");
                item.css("height", "0px");

                item.css("visibility", "visible");
                item.css("margin-bottom", "5px");

                item.animate({
                    height: itemHeight
                }, animationSpeed, function () {
                    // Animation complete.
                    item.css("height", "auto");
                });
            }

            jQuery(document).ready(function () {
                jQuery("h3").click(function (event) { //change h3 if you change faq title element
                    if (jQuery(event.target).parent().parent().is("div")) {

                        if (jQuery(event.target).parent().parent().attr('class') == 'myFAQ') {
                            var item = jQuery(event.target).next();
                            if (item.css("visibility") == "hidden") {
                                showItem(item);
                            }
                            else {
                                hideItem(item);
                            }
                        }
                    }
                });
            });
